<?php
$servername = "localhost";
$username = "username";
$password = "password";
 
// 创建连接
$conn = new mysqli($servername, $username, $password);
 
// 检测连接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
} 
echo "连接成功";
// 创建数据库
$sql = "CREATE DATABASE monitor";
if ($conn->query($sql) === TRUE) {
    echo "数据库创建成功";
} else {
    echo "Error creating database: " . $conn->error;
}

// 使用 sql 创建数据表
$sql = "CREATE TABLE log (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
level VARCHAR(32) NOT NULL,
data VARCHAR(2048) NOT NULL,
source VARCHAR(64),
clientip VARCHAR(64),
time VARCHAR(32),
savetime VARCHAR(32)
)";
 
if ($conn->query($sql) === TRUE) {
    echo "Table MyGuests created successfully";
} else {
    echo "创建数据表错误: " . $conn->error;
}

$conn->close();

?>